#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
#define endl "\n"
using namespace std;
struct jie
{
	int x,y;
};
int main()
{
	int t,n,mun=0,muny=0;
	cin>>t;
	jie a[51];
	while(t--)
	{
		cin>>n;
		mun=0,muny=0;
		for(int i=0;i<n;i++)
		{
			cin>>a[i].x>>a[i].y ;
		}
		for(int i=0;i<n;i++)
		{
			if(a[i].x<=10&&a[i].y>muny)
			{
				mun=i+1;
				muny=a[i].y ;
			}
		}
		cout<<mun<<endl;
	}
	return 0;
}